package info.xiao.algorithm.sort;

import java.util.Arrays;

/**
 * @Classname BubbleSort   冒泡排序
 * @Description
 * @Date 2022/10/10 11:01
 * @Created by 晓龙Oba
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] totalMarkArray = {280, 231, 236, 150, 297};
        totalMarkArray = sort(totalMarkArray);
        Arrays.stream(totalMarkArray).forEach(item -> System.out.println(item));
    }

    private static int[] sort(int[] totalMarkArray) {
        Boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = totalMarkArray.length - 1; i > 0; i--) {
                if (totalMarkArray[i] < totalMarkArray[i - 1]) {
                    flag = true;
                    totalMarkArray[i - 1] += totalMarkArray[i];
                    totalMarkArray[i] = totalMarkArray[i - 1] - totalMarkArray[i];
                    totalMarkArray[i - 1] -= totalMarkArray[i];
                }
            }
        }
        return totalMarkArray;
    }
}
